﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.APP.Application.Command.Breeds;
using Traceability.APP.Application.Command.Traceablitys;
using Traceability.APP.DTO;
using Traceability.Damoin;
using Traceability.ErrorCode;

namespace Traceability.APP.Controllers
{

    /// <summary>
    /// 养殖
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedsController : ControllerBase
    {
        private readonly IMediator mediator;

        public BreedsController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取养殖表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Breed>>> GetBreed([FromQuery]GetBreedCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddBreed(AddBreedCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 溯源修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateBreed(UpdateBreedCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 免疫新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddImmunity(AddImmunityCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 免疫修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateImmunity(UpdateImmunityCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 免疫删除
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> DeleteImmunity(int Id)
        {
            DeleteImmunityCommand request = new DeleteImmunityCommand()
            {
                Id= Id
            };
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取溯源表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Immunity>>> GetImmunity([FromQuery] GetImmunityCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 获取养殖企业表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Enterprise>>> GetEnterprise([FromQuery] GetEnterpriseCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 养殖企业新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddEnterprise(AddEnterpriseCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 养殖企业修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateEnterprise(UpdateEnterpriseCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
